<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('（网络理政区县）待受理来信M-处理页面')"/>
    <link th:href="@{/ajax/libs/bootstrap-tagsinput/tagsinput.css}" rel="stylesheet">
    <link th:href="@{/ajax/libs/jQuery-ui/jquery-ui.css}" rel="stylesheet">
    <link th:href="@{/css/iconfont/iconfont.css}" rel="stylesheet">
    <link rel="stylesheet" type="text/css" th:href="@{/ajax/libs/qxEasyUI/themes/default/easyui.css}">
</head>

<style>
    label {
        font-weight: bold;
    }

    @font-face {
        font-family: 'huawen';
        src: url("/fonts/huawen.woff2");
    }


</style>
<body style="background-color: #F4F6FA;letter-spacing:2px;font-family:'huawen' ;font-weight: bold">
<div class="main-content" style="margin: 0;padding: 0;">
    <form id="telInputForm" th:object="${mmailGetDeal}" class="form-horizontal" style="background-color: #F4F6FA">
        <input type="hidden" value="1" id="zjflag">
        <input id="pkId" name="pkId" th:field="*{pkId}" type="hidden">
        <input id="wsCode" name="wsCode" th:field="*{wsCode}" type="hidden">
        <input id="wsKey" name="wsKey" th:field="*{wsKey}" type="hidden">
        <input id="fmSpare" name="fmSpare" type="hidden" th:field="*{fmSpare}"/>
        <input id="txtAutoOpen" name="autoGetFlag" type="hidden" th:field="*{autoGetFlag}"/>
        <input id="fmCerNo" name="fmCerNo" type="hidden" th:field="*{fmCerNo}"/>
        <input id="fmCerName" name="fmCerName" type="hidden" th:field="*{fmCerName}"/>
        <input id="flagInt" name="flagInt" type="hidden" th:field="*{flagInt}"/>
        <input id="flagString" name="flagString" type="hidden" th:field="*{flagString}"/>
        <input id="spareInt" name="spareInt" type="hidden" th:field="*{spareInt}"/>
        <input id="spareString" name="spareString" type="hidden" th:field="*{spareString}"/>
        <input id="fkint" name="fkint" type="hidden" th:field="*{fkint}"/>
        <div class="col-sm-12 grid-container" style="display: flex">
            <!--     左       -->
            <div class="col-sm-8 entering-page">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required entering-pd">信件来源：</label>
                        <div class="col-sm-8">
                            <input name="fromTopic" th:field="*{spareString}" class="form-control" type="text" readonly>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required entering-pd">自动延期: </label>
                        <div class="col-sm-8">
                            <label class="check-box">
                                <input name="isAutoExtend" value="1" th:field="*{isAutoExtend}" type="radio">是
                            </label>
                            <label class="check-box">
                                <input name="isAutoExtend" value="0" th:field="*{isAutoExtend}" type="radio" checked>否
                            </label>
                        </div>
                    </div>
                </div>
                <div class="col-sm-12 entering-mt">
                    <div class="form-group">
                        <label class="col-sm-2 control-label is-required entering-pd">地区地址：</label>
                        <div class="col-sm-8">
                            <select name="fmAreaNo" th:field="*{fmAreaNo}" id="fmAreaNo"
                                    onchange="dropChgSendTextOnly(this,'fmAreaName');"
                                    th:with="district=${@commonServiceImpl.findArea()}" class="form-control formSelect"
                                    style="width: 120px;float:left;margin-right: 3px;"
                                    required>
                                <option value="">--请选择--</option>
                                <option th:each="item : ${district}" th:text="${item['CSText']}"
                                        th:value="${item['CSValue']}"></option>
                            </select>
                            <!--呈批-->
                            <input type="hidden" id="fmAreaName" name="fmAreaName" th:value="*{fmAreaName}"/>
                            <input name="fmAddress" th:field="*{fmAddress}" placeholder="请输入"
                                   class="form-control scene theAddress" type="text"
                                   maxlength="100" style="width: 200px;float:left;">
                            <button type="button" class="btn btn-sm btn-primary"
                                    style="margin:3px 0px 0px 15px;"
                                    th:if="${#strings.isEmpty(mmailGetDeal.flagString)}"
                                    onclick="transfer()" id="ZJ">呈批
                            </button>
                            <button type="button" class="btn btn-sm btn-primary"
                                    style="margin:3px 50px 0px 15px;"
                                    th:unless="${#strings.isEmpty(mmailGetDeal.flagString)}"
                                    title="呈批领导信箱" id="ZJOK">已呈批
                            </button>
                        </div>
                    </div>
                </div>

                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-sm-2 control-label is-required entering-pd">主题：</label>
                        <div class="col-sm-8">
                            <input name="fromTopic" th:field="*{fromTopic}" placeholder="请输入"
                                   class="form-control scene theAddress" type="text"
                                   maxlength="100"
                                   required="">
                        </div>
                    </div>
                </div>
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-xs-2 control-label is-required entering-pd">内容：</label>
                        <div class="col-xs-10">
                            <textarea name="fmContent" id="fmContent" th:field="*{fmContent}" maxlength="4000"
                                      class="form-control phoneRemark" rows="3"
                                      style="height: 100px" required></textarea>
                            <span>还可以输入<i class="phoneRemarkI">4000</i>个文字</span>

                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-4 control-label is-required entering-pd">来信人：</label>
                            <div class="col-sm-8">
                                <input name="fromName" th:field="*{fromName}" placeholder="请输入"
                                       class="form-control phoneName" type="text" required="">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-4 control-label is-required entering-pd">联系电话：</label>
                            <div class="col-sm-8">
                                <input name="fromTel" th:field="*{fromTel}" placeholder="请输入"
                                       class="form-control relationPhone"
                                       type="text"
                                       maxlength="20" required="">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-4 control-label is-required entering-pd">来信类别：</label>
                            <div class="col-sm-8">
                                <select name="dfmClaNo" id="dfmClaNo" required
                                        th:with="telTypes=${@commonServiceImpl.findTelType()}"
                                        onchange="dropChgSendTextOnly(this,'dfmClaName');"
                                        class="form-control formSelect">
                                    <option value="">--请选择--</option>
                                    <th:block th:each="item : ${telTypes}">
                                        <option th:text="${item['CSText']}" th:value="${item['CSValue']}"
                                                th:selected="${item['CSValue'] eq mmailGetDeal.dfmClaNo}"></option>
                                    </th:block>
                                </select>
                                <input type="hidden" name="dfmClaName" id="dfmClaName" th:value="*{dfmClaName}"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-4 control-label is-required entering-pd">内容类别：</label>
                            <div class="col-sm-8">
                                <input id="qxCT" th:value="*{dCntAName}"
                                       style="width:225px;height:31px;border-radius: 5px;">
                                <input id="txtDcntAcode" name="dCntACode" type="hidden" th:value="*{dCntACode}"/>
                                <input id="txtDCntAName" name="dCntAName" type="hidden" th:value="*{dCntAName}"/>
                            </div>
                        </div>
                    </div>
                </div>
                <!--关键词等-->
                <div class="col-sm-6">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-xs-4 control-label">建议公开：</label>
                            <div class="col-xs-8">
                                <label class="check-box">
                                    <input type="radio" name="openX" th:field="*{openX}" value="1">是
                                </label>
                                <label class="check-box">
                                    <input type="radio" name="openX" th:field="*{openX}" value="0">否
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-xs-4 control-label">同意公开：</label>
                            <div class="col-xs-8">
                                <label class="check-box">
                                    <input type="radio" name="openFrom" th:field="*{openFrom}" value="1">是
                                </label>
                                <label class="check-box">
                                    <input type="radio" name="openFrom" th:field="*{openFrom}" value="0">否
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-xs-4 control-label">重复来信：</label>
                            <div class="col-xs-8">
                                <label class="check-box">
                                    <input type="radio" name="repeatFlag" th:field="*{repeatFlag}" value="1">是
                                </label>
                                <label class="check-box">
                                    <input type="radio" name="repeatFlag" th:field="*{repeatFlag}" value="0">否
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-xs-4 control-label">性别：</label>
                            <div class="col-xs-8">
                                <label class="check-box">
                                    <input type="radio" name="fromSex" th:field="*{fromSex}" value="1">男
                                </label>
                                <label class="check-box">
                                    <input type="radio" name="fromSex" th:field="*{fromSex}" value="0">女
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
                <!--交办意见-->
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-xs-2 control-label entering-pd">处理意见：</label>
                        <div class="col-xs-10">
                            <div>
                                <div class="col-xs-5">
                                    <select style="margin-left: -14px;" id="xDealDescSelect"
                                            onchange="OftenMailWordsChg(this,'xdealDesc');"
                                            th:with="district=${@commonServiceImpl.findOpinionM()}"
                                            class="form-control formSelect">
                                        <option value="">--请选择--</option>
                                        <option th:each="item : ${district}" th:text="${item['CSText']}"
                                                th:value="${item['CSValue']}" th:data="${item['Remark']}"></option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-2 control-label entering-pd">答复内容：</label>
                        <div class="col-xs-10">
                            <textarea name="xdealDesc" th:field="*{xdealDesc}" id="xdealDesc" maxlength="3500"
                                      class="form-control opinion"
                                      rows="3"></textarea>
                            <span>还可以输入<i class="opinionI">3500</i>个文字</span>
                        </div>
                    </div>
                </div>
            </div>

            <!--右-->
            <div class="col-sm-4 ">
                <!--  接听人     接通时间       挂断时间等  -->
                <div class="col-sm-12 entering-page">
                    <!--左-->
                    <div class="col-sm-12" style="padding: 5px">
                        <div class="form-group" style="margin: 0">
                            <label class="col-sm-3 control-label  entering-pd" style="font-weight: bold">来信人：</label>
                            <div class="col-sm-8">
                                <span style="margin-top: 7px; display: inline-block">[[*{fromName}]]</span>
                            </div>
                        </div>
                        <div class="form-group" style="margin: 0">
                            <label class="col-sm-3 control-label  entering-pd" style="font-weight: bold">流水号：</label>
                            <div class="col-sm-8">
                                <span style="margin-top: 7px; display: inline-block">[[*{wsCode}]]</span>
                            </div>
                        </div>
                        <div class="form-group" style="margin: 0">
                            <label class="col-sm-3 control-label  entering-pd" style="font-weight: bold">提取码：</label>
                            <div class="col-sm-8">
                                <span style="margin-top: 7px; display: inline-block">[[*{wsKey}]]</span>
                            </div>
                        </div>
                        <div class="form-group" style="margin: 0">
                            <label class="col-sm-3 control-label  entering-pd"
                                   style="font-weight: bold">联系电话：</label>
                            <div class="col-sm-8">
                                <span style="margin-top: 7px; display: inline-block">[[*{fromTel}]]</span>
                            </div>
                        </div>
                        <div class="form-group" style="margin: 0">
                            <label class="col-sm-3 control-label  entering-pd"
                                   style="font-weight: bold">来信时间：</label>
                            <div class="col-sm-8">
                                <span style="margin-top: 7px; display: inline-block" id="hangup"
                                      th:text="*{#calendars.format(fromTime,'yyyy-MM-dd HH:mm:ss')}"></span>
                            </div>
                        </div>
                        <div class="form-group" style="margin: 0">
                            <label class="col-sm-3 control-label  entering-pd"
                                   style="font-weight: bold">电子邮件：</label>
                            <div class="col-sm-8">
                                <span style="margin-top: 7px; display: inline-block">[[*{fmEmail}]]</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <div class="col-sm-12 pb15">
            <!-- 按钮-->
            <div class="col-sm-12"
                 style="margin-bottom: 10px;display: flex;justify-content: center;flex-direction: row;">
                <button type="button" class="btn btn-sm btn-primary" onclick="temStorage('未处理','1411')">修改
                </button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <button type="button" class="btn btn-sm btn-info" onclick="directReply('直接答复','1611')">直接答复
                </button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <button type="button" class="btn btn-sm btn-success" onclick="draft('无效来信 当场作废','1621')">作废
                </button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <button type="button" class="btn btn-sm btn-info" onclick="createWorkorder()">创建工单
                </button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <button type="button" class="btn btn-sm btn-warning" onclick="gclose()">关闭
                </button>&nbsp;
                <input id="tbStateDesc" name="stateDesc" th:field="*{stateDesc}" type="hidden"/>
                <input id="stateFlag" name="stateFlag" th:field="*{stateFlag}" type="hidden"/>
            </div>
        </div>
    </form>
</div>

<script th:src="@{/ajax/libs/layui/laydate.js}"></script>
<th:block th:include="include :: footer"/>
<script th:src="@{/ajax/libs/qxEasyUI/jquery.easyui.min.js}"></script>
<script>
    var prefix = ctx + "system/wsMail";

    //    存草稿
    function draft(fpStr, str) {
        $("#tbStateDesc").val(fpStr);
        $('#stateFlag').val(str);
        if ($.validate.form()) {
            let data = $('#telInputForm').serializeArray();
            $.operate.saveTab(prefix + "/edit", data);
        }
    }

    //直接答复
    function directReply(fpStr, str) {
        $("#tbStateDesc").val(fpStr);
        $('#stateFlag').val(str);
        var replyDesc = $('#xdealDesc').val();
        var flag = false;
        flag = $.validate.form();
        if (replyDesc.length == 0) {
            $('#xdealDesc').addClass('error');
            $('#xdealDesc').focus();
            layer.msg("请填写答复内容", {icon: 2, time: 2000});
            return;
        }
        if ($("#txtDcntAcode").val() == '') {
            $('.combo-text').addClass('error');
            flag = false;
        } else {
            $('.combo-text').removeClass('error');
        }
        if (flag) {
            let data = $('#telInputForm').serializeArray();
            $.operate.saveTab(prefix + "/edit", data);
        }
    }

    $('#xdealDesc').keyup(function () {
        var xdealDesc = document.getElementById('xdealDesc').value.trim();
        if (xdealDesc.length > 0) {
            $('#xdealDesc').removeClass('error');
        }
    })

    // 暂存
    function temStorage(fpStr, str) {
        $("#tbStateDesc").val(fpStr);
        $('#stateFlag').val(str);
        if ($.validate.form()) {
            let data = $('#telInputForm').serializeArray();
            var config = {
                url: prefix + "/edit",
                type: "post",
                dataType: "json",
                data: data,
                success: function (result) {
                    $.modal.msgSuccess('操作成功');
                }
            };
            $.ajax(config);
        }
    }

    function createWorkorder() {
        if ($('#fmContent').val() == '') {
            return $.modal.alertWarning('温馨提示:请输入来信内容');
        }
        let data = $('#telInputForm').serializeArray();
        var config = {
            url: prefix + '/createWorkform',
            type: "post",
            dataType: "json",
            data: data,
            success: function (result) {
                // $.operate.ajaxSuccess(result);
                // refreshCountyNotAcceptList();
                $.operate.ajaxTabSuccess(result);
                var url = prefix + '/tworkform/' + result.pkId;
                $.modal.parentTab('拟派工单', url);
            }
        };
        $.ajax(config);
    }

    $('#qxCT').combotree({
        url: '/system/common/findContentCate',
        required: false,
        onSelect: function (record) {
            $("#txtDcntAcode").val(record.id);
            $("#txtDCntAName").val(record.text);
            $('.combo-text').removeClass('error');
        }
    });

    //    关闭
    function gclose() {
        $.modal.closeTab();
    }


    function OftenMailWordsChg(e, acpId) {
        temp = $(e.options[e.selectedIndex]).attr('data');
        document.getElementById(acpId).value = temp;
    }

    // 刷新待区县受理信件列表页
    function refreshCountyNotAcceptList() {
        var navFrame = $('.NAP_iframe[data-id="/system/wsMail/listWaitGetXZ"]', parent.document)[0];
        navFrame.contentWindow.$.table.refresh();
    }

    //呈批
    function transfer() {
        if ($("#ZJ").text() == '已呈批') return false;
        var fmSpare = $('#fmSpare').val();
        //网络理政件呈批
        if (fmSpare < 50000) {
            var params = {
                flag: $("#zjflag").val(),
                flagString: "呈批至" + $("#spareString").val() + "的信箱",
                spareString: $("#spareString").val(),
                ddlTelSort: $("#dfmClaNo option:selected").val(),
                ddlArea: $("#fmAreaNo option:selected").val(),
                txtDcntAcode: $("#txtDcntAcode").val(),
                pkId: $("#pkId").val()
            };
            commitAjaxForm(params);
        }
        //后台自建信件呈批
        else if (fmSpare >= 50000) {
            let url = ctx + "system/wsMail/submitForApproval";
            var config = {
                id: 'forApproval',
                title: '请选择呈批信箱',
                width: '50%',
                height: '65%',
                url: url,
                callBack: forApproval
            };
            $.modal.openOptions(config);
        }
    }

    function forApproval(index, layero) {
        let rows = layero.find("iframe")[0].contentWindow.getSelections();
        if (rows.length === 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var flagString = rows[0].submit_name + rows[0].name;
        var params = {
            flag: $("#zjflag").val(),
            flagString: "呈批至" + flagString + "的信箱",
            spareString: rows[0].submit_name + rows[0].name,
            ddlTelSort: $("#dfmClaNo option:selected").val(),
            ddlArea: $("#fmAreaNo option:selected").val(),
            txtDcntAcode: $("#txtDcntAcode").val(),
            pkId: $("#pkId").val(),
            mailboxNo: rows[0].submit_id
        };
        commitAjaxForm(params);
        $.modal.close(index);
    }

    function commitAjaxForm(params) {
        $.modal.confirm("是否确定呈批：" + params.flagString, function () {
            let url = ctx + "system/wsMail/forApproval";
            $.ajax({
                url: url,
                type: "post",
                data: params,
                dataType: "json",
                beforeSend: function () {
                    $("#ZJ").prop("disabled", true);
                    beforeSend();
                },
                success: function (result) {
                    if (result.msg == "操作成功") {
                        $.modal.msgSuccess('呈批成功！');
                        $("#ZJ").text('已呈批');
                        $("#ZJ").unbind('click');
                    } else {
                        $.modal.msgError(result.msg);
                    }
                },
                complete: function () {
                    $("#ZJ").prop("disabled", false);
                    completeSend();
                }
            });
        })
    }
</script>
</body>
</html>

